package pnu.ssm.controller.manager;

import java.util.ArrayList;
import java.util.Iterator;

import pnu.ssm.model.stuff.Block;


// Singleton Pattern
// Iterator Pattern
public class BlockManager implements Iterable<Block>{
	private ArrayList<Block> blocks;
	
	private static BlockManager instance = new BlockManager();
	private BlockManager() {
		blocks = new ArrayList<Block>();
	}
	public static BlockManager getInstance(){
		return instance;
	}
	
	public void init(){
		blocks.clear();
	}
	
	public void addBlock(Block b){
		blocks.add(b);
	}
	
	public Block getBlock(String name){
		Block tempBlock = null;
		Iterator<Block> it = blocks.iterator();
		while(it.hasNext()){
			tempBlock = it.next();
			if(tempBlock.getName().equals(name)){
				return tempBlock;
			}
		}
		return tempBlock;
	}

	@Override
	public Iterator<Block> iterator() {
		return blocks.iterator();
	}
}
